<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *密码修改
 */
if(0){?><script><?php }?>

    Ext.define('Hydcrm.user.UserPassWindow', {
        extend: 'Ext.Window',
        constructor: function(config) {  //alert("1111");
            config = config || {};
            
            config.id = 'user_pass_window';
            config.title = "修改个人密码";
            config.width = 500;
            config.iconCls = 'icon-pass';
            config.items = this.buildForm();

            config.buttons = [
                {
                    text: '保存',
                    handler: function() {
                        this.submitForm();
                    },
                    scope: this
                }
            ];

            this.addEvents({'notifysuccess': true});
            this.addEvents({'savesuccess': true});

            this.callParent([config]);
        },
        buildForm: function() {
            //自定义vtype  
            Ext.apply(Ext.form.VTypes, {
                password: function(val, field) {                   //val指这里的文本框值，field指这个文本框组件，
                    if (field.confirmTo) {                          //confirmTo是我们自定义的配置参数，一般用来保存另外的组件的id值
                        var pwd = Ext.getCmp(field.confirmTo);      //取得confirmTo的那个id的值 
                        return (val === pwd.getValue());
                    }
                    return true;
                }
            });
            this.frmUserPass= Ext.create('Ext.form.FormPanel', {
                    url: Hydcrm.CONF.CONN_URL,
                    baseParams: {
                        module: 'user',
                        action: 'edit_password'
                    },
                    border: false,
                    bodyPadding: 10,
                    fieldDefaults: {
                        labelAlign: 'left',
                        labelWidth: 149,
                        msgTarget: 'side',
                        anchor: '98%'
                    },
                    items: [
                        {xtype: 'textfield', fieldLabel: '原密码', name: 'password', allowBlank: false},
                        {xtype: 'textfield', fieldLabel: '新密码', name: 'password_new',id: 'password', inputType: 'password'},
                        {xtype: 'textfield', fieldLabel:'确认新密码', inputType: 'password', id: 'repassword_new',
                            vtype: "password",
                            vtypeText: '两次密码不一致！',
                            confirmTo: "password"        //确认密码要比较另外一个的组件的id                                                                           
                        }
                    ]
                });
            return this.frmUserPass;
        },

        submitForm: function() {
            this.frmUserPass.form.submit({
                waitMsg: '正在提交请稍候',
                success: function(form, action) { //this.fireEvent('savesuccess', action.result.feedback);
                    Ext.Msg.alert("提示信息", action.result.feedback);
                    this.close();
                    //window.location = 'index.php/login/loginout';
                },
                failure: function(form, action) {
                    if (action.failureType != 'client') {
                        //Ext.Msg.alert("错误", action.result.feedback);
                    }
                },
                scope: this
            });
        }

    });